<?php

/**
 * default Components.
 *
 * @package    social
 * @subpackage default
 * @author     Your name here
 * @version    SVN: $Id: Components.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class plikizewnetrzneComponents extends sfComponents
{
  
  public function executeForm()
  {
    $this->form = new ProwadzacyMetaDataForm();
    $this->form2 = new sfGuardRegisterFormExtraField();
    
  }
  public function executeSprawdzPlikZewnetrzny(sfWebRequest $request)
  {  
    $user = $this->user = $this->getUser()->getGuardUser();
    
    $external_file = Doctrine_Core::getTable('prowadzacyMetaData')
        ->createQuery('e')
        ->where('e.user_id = ?', $user->id);
    
    $ile_rekordow = $external_file->count();
    
    // Sprawdz czy plik zostal kiedykolwiek utworzony
    if($ile_rekordow == 0):
        $this->file_status = 'Create new';    
    else:
        $external_file = $this->external_file = $external_file->fetchOne();
        $filename = $external_file->external_file_location;
        // Sprawdz czy w bazie nie ma pustego rekordu
        if($filename == null){
            $this->file_status = 'Empty record';
        }
        // Sprawdz czy adres z bazy wskazuje na plik
        elseif (is_writable($filename)){
            $this->file_status = $external_file; 
        } else {
            $this->file_status = 'File do not match';            
        }
    endif;
    
  }

  
}